package com.river.springbootdemo.thinkingjava.objectrefer;

import java.util.List;
import java.util.ListIterator;

/**
 * 演示ListIterator双向遍历以及制定位置开始遍历
 */
public class ListIteration {
    public static void main(String[] args) {
        List<Pet> pets = Pets.arrayList(8);
        ListIterator<Pet> it = pets.listIterator();
        while (it.hasNext()) {
            Pet p = it.next();
            System.out.print(p.getId() + ":" + p + "  ");
        }
        System.out.println();
        while (it.hasPrevious()) {
            Pet p = it.previous();
            System.out.print(p.getId() + ":" + p + "  ");
        }
        System.out.println();
        it = pets.listIterator(3);
        while (it.hasNext()) {
            Pet p = it.next();
            System.out.print(p.getId() + ":" + p + "  ");
        }
        System.out.println();
        System.out.println(pets);
    }
}
